package com.touchealth.test.mail;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author zhangyanqiang
 * @date 2021/5/25
 **/
public class MailUtil {

    /**
     * 是订单项以type分组编号
     *
     * @param smOrderItemBos
     * @return
     */
    private Map<Integer, List<String>> smOrderItemGroupingByType(List<SmOrderItemBo> smOrderItemBos) {
        Map<Integer, List<String>> typeToNoMap = smOrderItemBos.stream().collect(Collectors.toMap(SmOrderItemBo::getType, smOrderItemBo -> {
                    List<String> strs = new ArrayList<>();
                    strs.add(smOrderItemBo.getPlanNo());
                    return strs;
                }, (x, y) -> {
                    x.addAll(y);
                    return x;
                }
        ));
        return typeToNoMap;
    }

    public static int getYear(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.YEAR);
    }

    public static int getMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.MONTH)+1;
    }

    public static int getDayOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.DAY_OF_MONTH);
    }

    public static int getAgeByBirth(Date birthday) {
        String startDate = "2021-07-01";
        String[] dateStrings = StringUtils.split(startDate, "-");
        /*取出当前年月日*/
        int yearNow = Integer.parseInt(dateStrings[0]);
        int monthNow = Integer.parseInt(dateStrings[1]);
        int dayNow = Integer.parseInt(dateStrings[2]);
        /*取出出生年月日*/
        int yearBirth = getYear(birthday);
        int monthBirth = getMonth(birthday);
        int dayBirth = getDayOfMonth(birthday);
        /*大概年龄是当前年减去出生年*/
        int age = yearNow - yearBirth;
        /*如果出当前月小与出生月，或者当前月等于出生月但是当前日小于出生日，那么年龄age就减一岁*/
        if (monthNow < monthBirth || (monthNow == monthBirth && dayNow < dayBirth)) {
            age--;
        }
        return age;
    }

    public static void main(String[] args) {

//        BigDecimal new1 = new BigDecimal("1.1");
//
//        BigDecimal new2 = BigDecimal.ONE;
//        SmOrderItemBo smOrderItemBo = new SmOrderItemBo();
//        smOrderItemBo.setItemScore(new1);
//
//        System.out.println(smOrderItemBo.getItemScore());

          System.out.println(Boolean.FALSE.equals(Boolean.FALSE));

          Date dateNow = DateUtil.parse("2021-01-10 00:00:01","MM");


          System.out.println(DateUtil.month(DateUtil.date()));

    }

}
